home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS5.ZIP / DOSENVN < prev    next >
Text File  |  1986-11-25  |  8KB  |  132 lines

  1.                     DOS's Dynamic Environment
  2.             (PC World September 1986 The Help Screen)
  3.  
  4.      The DOS environment area is one place where parameters can be
  5. passed from one program or batch file to another.  For example, to
  6. indicate the presence of a mouse, the AUTOEXEC.BAT file might issue
  7. the command SET MOUSE=1.  The another batch file could include the
  8. conditional line IF "%MOUSE%"=="1" COPY mouse.drv PDIO.EXE before
  9. loading TopView.  The % signs tell DOS to search the environment
  10. area for a line starting with MOUSE; if MOUSE=1, the condition is
  11. true and the mouse driver file is copied to PDIO.EXT for use by
  12. TopView.
  13.      This approach can also be used within programs to access the DOS
  14. environment to determine what parameters have been SET.  When you
  15. enter an external command -- for example, to load BASIC or APL -- or
  16. call a program via the EXEC function call, DOS puts the program 256
  17. bytes above the lowest block of memory that can hold the program
  18. being started.  The first 256 bytes constitutes the Program Segment
  19. Prefix (PSP), a control block that includes the segment address of a
  20. copy of the DOS environment area.  That segment address is kept in the
  21. PSP at offsets 2C and 2D.
  22.      When an .EXE program starts, the DS and ES registers are set to
  23. point to the beginning of the PSP.  When a .COM program is started,
  24. all four segment registers are set to point there.  You should
  25. remember, especially if yours is a TSR application, that the copy of
  26. the environment area is static; it is the invoking process's current
  27. environment.  Subsequently issued SET, PATH, and PROMPT commands will
  28. not change the environment area copy.
  29.      The PSP contains other information that your programs may find
  30. useful.  In particular, a copy of the parameters following the
  31. invoking command (including leading blanks) can be found in the PSP
  32. at offset 81 hex; offset 80 notes the number of characters.  Using
  33. this information, a program could bypass its opening menu and proceed
  34. directly to some function that the user specifies on the DOS command
  35. line when the program is called.  You can find more information on
  36. DOS program and file control blocks in the DOS Technical Reference
  37. manual.
  38.  
  39. -----------------------------------------------------------------
  40.                       Environment Expansion
  41.          (PC Tech Journal November 1986 by Jim Vallino)
  42.  
  43.      DOS 2.0 marked the first appearance of the environment feature --
  44. a block of memory reserved by the operating system to hold several
  45. system environment variables and equated ASCII strings.  Whenever a
  46. program is run, the operating system makes a copy of the environment
  47. and then passes to the program the segment address of this copy at
  48. offset 2Ch in the program segment prefix (PSP).  Many applications
  49. search this environment for variables that specify user preferences
  50. for information such as the directories in which auxiliary files are
  51. placed.
  52.      The user manages the environment variables using the SET command.
  53. Variables may be added, deleted, changed, or displayed with this
  54. command.  Memory space for the environment is allocated during the
  55. booting of COMMAND.COM using the Allocate Memory (48h) function of
  56. DOS.  This block of memory is placed just above the resident portion
  57. of the operating system with a default initial size of 10 paragraphs
  58. (160 bytes).  As variables are added, the environment is increased up
  59. to a maximum of 32KB provided that contiguous memory space is
  60. available for the increase in size.
  61.      Unfortunately, expansion of the environment is often prevented.
  62. Just beyond DOS's environment memory block is the free memory used for
  63. loading application programs.  When a program is loaded into this area
  64. it limits the size of the environment to its current memory allocation.
  65. If this program is one of the many utilities that remains resident,
  66. then the size limitation is permanent.  Even if no terminate-and-stay-
  67. resident programs are run, defining many environment strings from the
  68. command line can be tedious.
  69.      What most users would like to do is place all of the SET commands
  70. into a batch file such as AUTOEXEC.BAT.  However, the operating system
  71. will load information for the running of this batch file just above
  72. the environment, effectively freezing its current size.  The solution
  73. is to increase the number of paragraphs requested for the default
  74. environment memory block.  This is done in DOS 2.x and 3.0 by patching
  75. COMMAND.COM, whereas in versions 3.1 and 3.2 a feature of the SHELL
  76. command makes a patch unnecessary.
  77.      Whenever attempting to patch the operating system the user should
  78. perform the work on a backup copy of the DOS diskette in case something
  79. goes wrong.  The new copy should be placed in drive A: and
  80. DEBUG A:COMMAND.COM run.  The relevant assembly code is:
  81.  
  82. Assembly Code    Machine Code
  83. -------------    ------------
  84. MOV BX,0A    BB 0A 00    ;Load BX with number of paragraphs
  85. MOV AH,48    B4 48        ;Specify Allocate Memory function
  86. INT 21        CD 21        ;Execute DOS function
  87.  
  88. Use the DEBUG command S 100 L 4500 BB 0A 00 B4 48 CD 21 to find the
  89. location of this piece of code.  Unassembling the program at this
  90. location should display the first three instructions shown above.
  91. If the instructions do not correspond, the operation steps should be
  92. checked again.  (This code does not appear in DOS 3.1 and 3.2; if
  93. these versions are being used, see the section below for the correct
  94. procedure to follow.)  At the address displayed, assemble a new
  95. instruciton, which loads the BX register with the size desired.
  96. Remember that the number loaded into BX is understood as a hexadecimal
  97. value specifying the number of paragraphs (times 16 for bytes) in the
  98. default environment.  Check the modification by then unassembling
  99. again.
  100.      Once the change is satisfactory, write it back to the diskette
  101. and exit DEBUG.  Then reboot from this diskette and perform a simple
  102. operation (such as DIR) to see if the operating system still functions.
  103. If it still functions correctly, copy the patched COMMAND.COM to the
  104. root directory of the disk from which the computer is normally booted.
  105. Be sure that a backup of the patched version of the operating system
  106. is made to be restored to the boot disk if ever needed.
  107.      To verify that the environment is enlarged, create a batch file
  108. with several SET commands, which define strings with a total of more
  109. that 160 bytes but less than the new size of the environment.  Typing
  110. SET without any parameters lists the entire contents of the modified
  111. environment.
  112.      Beginning with DOS 3.1, a feature of COMMAND.COM and the SHELL
  113. statement used in CONFIG.SYS allows a user to specify the size of the
  114. default environment.  This feature was not documented in the IBM
  115. literature until DOS 3.2, although it is available in a slightly
  116. different form in DOS 3.1.  The IBM DOS 3.1 documentation does not
  117. mention that the SHELL command includes an option that defines the
  118. size of the default environment.
  119.      Put a SHELL statement in the CONFIG.SYS file using the following
  120. command format:
  121.  
  122. SHELL<command-file> /P /E:xx
  123.  
  124. where <command-file> is the full path name for COMMAND.COM, and xx is
  125. the size of the default environment.  This size is given as a decimal
  126. value representing in version 3.1 the number of paragraphs in the
  127. environment and in version 3.2 the number of bytes.  The P option
  128. instructions COMMAND.COM to execute the AUTOEXEC.BAT file, or date
  129. and time if no AUTOEXEC.BAT is present when the command processor is
  130. loaded.
  131.  
  132.